<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        a{
            text-decoration: none;
            font-size: 30px;
            margin-left: 30px;
        }
        html,body{
            width: 100%;
            height: 100%;
        }
        .mask{
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,.3);
            display: none;
        }
        .box{
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            z-index: 10;
            width: 300px;
            height: 300px;
            background-color: red;
            display: none;
        }
    </style>
</head>
<body>
    <a href="#">注册</a>
    <div class="mask"></div>
    <div class="box"></div>
</body>
<script>
    var hyperlink = document.querySelector('a')
    var mask = document.querySelector('.mask')
    var box = document.querySelector('.box')
    //为a标签注册点击事件
    hyperlink.onclick = function(event){
        //event事件兼容IE
        event = event || window.event
        mask.style.display = 'block'
        box.style.display = 'block'
        //判断event是否有stopPropagation
        if (event.stopPropagation) {
            //stopPropagation()是w3c标准的阻止冒泡的
            event.stopPropagation()
        }else{
            //window.event.cancelBubble = true;默认值是false，这个是兼容IE浏览器的
            window.event.cancelBubble = true;
        }
    }
    document.onclick = function(){
        mask.style.display = 'none'
        box.style.display = 'none'
    }
</script>
</html>